package com.huonan.utils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.StopWatch;
import cn.hutool.db.nosql.redis.RedisDS;
import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.Jedis;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Slf4j
public class RedisUtil {
    public static void main(String[] args) {
        RedisDS redisCli = RedisDS.create();
        //Jedis jedis = redisCli.getJedis();
        //String s = jedis.get("das.username.0004139");
        //String str = redisCli.getStr("das.username.0004158");
        //  System.out.println(str);
        StopWatch stopWatch = DateUtil.createStopWatch("redis task");
        Jedis jedis = redisCli.getJedis();
        String key = "i7s_douyin_article_ids";
        stopWatch.start(key + "-search Data");
        // addData(jedis, key);
        jedis.sadd(key,"7246141595626573093");
        jedis.sadd(key,"7246141715663375671");
        jedis.sadd(key,"7246141756956347659");
        stopWatch.stop();
        //获取数量
//        Long scard = jedis.scard(key);
//        log.info("scard cound:{}",scard);
        // 添加set 集合，bath add
        // jedis.sadd(key, "");
        // 获取全部set 集合
        // Set<String> smembers = jedis.smembers(key);
//        stopWatch.start("sismember key");
        //判断set集合是否存在某个成员


        //System.out.println(smembers);
    }

    private static void addData(Jedis jedis, String key) {
        for (int i = 0; i < 10; i++) {
            jedis.hset(key, i + "_" + UUID.randomUUID(), "");
        }
    }

    private static String[] pruduceData() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            list.add(i + "_" + UUID.randomUUID());
        }
        return list.toArray(new String[0]);
    }

}
